/*!
 AutoFill 2.1.0
 ©2008-2015 SpryMedia Ltd - datatables.net/license
*/
(function(e){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(k){return e(k,window,document)}):"object"===typeof exports?module.exports=function(k,i){k||(k=window);if(!i||!i.fn.dataTable)i=require("datatables.net")(k,i).$;return e(i,k,k.document)}:e(jQuery,window,document)})(function(e,k,i,r){var j=e.fn.dataTable,o=0,g=function(c,b){if(!j.versionCheck||!j.versionCheck("1.10.8"))throw"Warning: AutoFill requires DataTables 1.10.8 or greater";this.c=e.extend(!0,{},j.defaults.autoFill,
g.defaults,b);this.s={dt:new j.Api(c),namespace:".autoFill"+o++,scroll:{},scrollInterval:null,handle:{height:0,width:0}};this.dom={handle:e('<div class="dt-autofill-handle"/>'),select:{top:e('<div class="dt-autofill-select top"/>'),right:e('<div class="dt-autofill-select right"/>'),bottom:e('<div class="dt-autofill-select bottom"/>'),left:e('<div class="dt-autofill-select left"/>')},background:e('<div class="dt-autofill-background"/>'),list:e('<div class="dt-autofill-list">'+this.s.dt.i18n("autoFill.info",
"")+"<ul/></div>"),dtScroll:null,offsetParent:null};this._constructor()};e.extend(g.prototype,{_constructor:function(){var c=this,b=this.s.dt,a=e("div.dataTables_scrollBody",this.s.dt.table().container());a.length&&(this.dom.dtScroll=a,"static"===a.css("position")&&a.css("position","relative"));this._focusListener();this.dom.handle.on("mousedown",function(a){c._mousedown(a);return false});b.on("destroy.autoFill",function(){b.off(".autoFill");e(b.table().body()).off(c.s.namespace);e(i.body).off(c.s.namespace)})},
_attach:function(c){var b=this.s.dt,a=b.cell(c).index(),d=this.dom.handle,f=this.s.handle;if(!a||-1===b.columns(this.c.columns).indexes().indexOf(a.column))this._detach();else{this.dom.offsetParent||(this.dom.offsetParent=e(c).offsetParent());if(!f.height||!f.width)d.appendTo("body"),f.height=d.outerHeight(),f.width=d.outerWidth();b=e(c).position();this.dom.attachedTo=c;d.css({top:b.top+c.offsetHeight-f.height,left:b.left+c.offsetWidth-f.width}).appendTo(this.dom.offsetParent)}},_actionSelector:function(c){var b=
this,a=this.s.dt,d=g.actions,f=[];e.each(d,function(b,d){d.available(a,c)&&f.push(b)});if(1===f.length&&!1===this.c.alwaysAsk){var l=d[f[0]].execute(a,c);this._update(l,c)}else{var h=this.dom.list.children("ul").empty();f.push("cancel");e.each(f,function(f,l){h.append(e("<li/>").append('<div class="dt-autofill-question">'+d[l].option(a,c)+"<div>").append(e('<div class="dt-autofill-button">').append(e('<button class="'+g.classes.btn+'">'+a.i18n("autoFill.button","&gt;")+"</button>").on("click",function(){var f=
d[l].execute(a,c,e(this).closest("li"));b._update(f,c);b.dom.background.remove();b.dom.list.remove()}))))});this.dom.background.appendTo("body");this.dom.list.appendTo("body");this.dom.list.css("margin-top",-1*(this.dom.list.outerHeight()/2))}},_detach:function(){this.dom.attachedTo=null;this.dom.handle.detach()},_drawSelection:function(c){var b=this.s.dt,a=this.s.start,d=e(this.dom.start),f=e(c),l={row:b.rows({page:"current"}).nodes().indexOf(f.parent()[0]),column:f.index()};if(b.cell(f).any()&&
-1!==b.columns(this.c.columns).indexes().indexOf(l.column)){this.s.end=l;var h,b=a.row<l.row?d:f;h=a.row<l.row?f:d;c=a.column<l.column?d:f;d=a.column<l.column?f:d;b=b.position().top;c=c.position().left;a=h.position().top+h.outerHeight()-b;d=d.position().left+d.outerWidth()-c;if(f=this.dom.dtScroll)b+=f.scrollTop(),c+=f.scrollLeft();f=this.dom.select;f.top.css({top:b,left:c,width:d});f.left.css({top:b,left:c,height:a});f.bottom.css({top:b+a,left:c,width:d});f.right.css({top:b,left:c+d,height:a})}},
_editor:function(c){var b=this.s.dt,a=this.c.editor;if(a){for(var d={},f=[],e=a.fields(),h=0,i=c.length;h<i;h++)for(var g=0,k=c[h].length;g<k;g++){var n=c[h][g],j=b.settings()[0].aoColumns[n.index.column],m=j.editField;if(m===r)for(var j=j.mData,p=0,o=e.length;p<o;p++){var q=a.field(e[p]);if(q.dataSrc()===j){m=q.name();break}}if(!m)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";d[m]||(d[m]={});j=b.row(n.index.row).id();d[m][j]=n.set;f.push(n.index)}a.bubble(f,
!1).multiSet(d).submit()}},_emitEvent:function(c,b){this.s.dt.iterator("table",function(a){e(a.nTable).triggerHandler(c+".dt",b)})},_focusListener:function(){var c=this,b=this.s.dt,a=this.s.namespace,d=null!==this.c.focus?this.c.focus:b.settings()[0].keytable?"focus":"hover";if("focus"===d)b.on("key-focus.autoFill",function(a,b,d){c._attach(d.node())}).on("key-blur.autoFill",function(){c._detach()});else if("click"===d)e(b.table().body()).on("click"+a,"td, th",function(){c._attach(this)}),e(i.body).on("click"+
a,function(a){e(a.target).parents().filter(b.table().body()).length||c._detach()});else e(b.table().body()).on("mouseenter"+a,"td, th",function(){c._attach(this)}).on("mouseleave"+a,function(a){e(a.relatedTarget).hasClass("dt-autofill-handle")||c._detach()})},_mousedown:function(c){var b=this,a=this.s.dt;this.dom.start=this.dom.attachedTo;this.s.start={row:a.rows({page:"current"}).nodes().indexOf(e(this.dom.start).parent()[0]),column:e(this.dom.start).index()};e(i.body).on("mousemove.autoFill",function(a){b._mousemove(a)}).on("mouseup.autoFill",
function(a){b._mouseup(a)});var a=this.dom.select,d=e(this.s.dt.table().body()).offsetParent();a.top.appendTo(d);a.left.appendTo(d);a.right.appendTo(d);a.bottom.appendTo(d);this._drawSelection(this.dom.start,c);this.dom.handle.css("display","none");c=this.dom.dtScroll;this.s.scroll={windowHeight:e(k).height(),windowWidth:e(k).width(),dtTop:c?c.offset().top:null,dtLeft:c?c.offset().left:null,dtHeight:c?c.outerHeight():null,dtWidth:c?c.outerWidth():null}},_mousemove:function(c){var b=c.target.nodeName.toLowerCase();
"td"!==b&&"th"!==b||(this._drawSelection(c.target,c),this._shiftScroll(c))},_mouseup:function(){e(i.body).off(".autoFill");var c=this.s.dt,b=this.dom.select;b.top.remove();b.left.remove();b.right.remove();b.bottom.remove();this.dom.handle.css("display","block");var b=this.s.start,a=this.s.end;if(!(b.row===a.row&&b.column===a.column)){for(var d=this._range(b.row,a.row),b=this._range(b.column,a.column),a=[],f=0;f<d.length;f++)a.push(e.map(b,function(a){a=c.cell(":eq("+d[f]+")",a+":visible",{page:"current"});
return{cell:a,data:a.data(),index:a.index()}}));this._actionSelector(a)}},_range:function(c,b){var a=[],d;if(c<=b)for(d=c;d<=b;d++)a.push(d);else for(d=c;d>=b;d--)a.push(d);return a},_shiftScroll:function(c){var b=this,a=this.s.scroll,d=!1,f=c.pageY-i.body.scrollTop,e=c.pageX-i.body.scrollLeft,h,g,j,k;65>f?h=-5:f>a.windowHeight-65&&(h=5);65>e?g=-5:e>a.windowWidth-65&&(g=5);null!==a.dtTop&&c.pageY<a.dtTop+65?j=-5:null!==a.dtTop&&c.pageY>a.dtTop+a.dtHeight-65&&(j=5);null!==a.dtLeft&&c.pageX<a.dtLeft+
65?k=-5:null!==a.dtLeft&&c.pageX>a.dtLeft+a.dtWidth-65&&(k=5);h||g||j||k?(a.windowVert=h,a.windowHoriz=g,a.dtVert=j,a.dtHoriz=k,d=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null);!this.s.scrollInterval&&d&&(this.s.scrollInterval=setInterval(function(){if(a.windowVert)i.body.scrollTop=i.body.scrollTop+a.windowVert;if(a.windowHoriz)i.body.scrollLeft=i.body.scrollLeft+a.windowHoriz;if(a.dtVert||a.dtHoriz){var c=b.dom.dtScroll[0];if(a.dtVert)c.scrollTop=c.scrollTop+
a.dtVert;if(a.dtHoriz)c.scrollLeft=c.scrollLeft+a.dtHoriz}},20))},_update:function(c,b){if(!1!==c){var a=this.s.dt,d;this._emitEvent("preAutoFill",[a,b]);this._editor(b);if(null!==this.c.update?this.c.update:!this.c.editor){for(var f=0,e=b.length;f<e;f++)for(var h=0,g=b[f].length;h<g;h++)d=b[f][h],d.cell.data(d.set);a.draw(!1)}this._emitEvent("autoFill",[a,b])}}});g.actions={increment:{available:function(c,b){return e.isNumeric(b[0][0].data)},option:function(c){return c.i18n("autoFill.increment",
'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(c,b,a){for(var c=1*b[0][0].data,a=1*e("input",a).val(),d=0,f=b.length;d<f;d++)for(var l=0,h=b[d].length;l<h;l++)b[d][l].set=c,c+=a}},fill:{available:function(){return!0},option:function(c,b){return c.i18n("autoFill.fill","Fill all cells with <i>"+b[0][0].data+"</i>")},execute:function(c,b){for(var a=b[0][0].data,d=0,f=b.length;d<f;d++)for(var e=0,h=b[d].length;e<h;e++)b[d][e].set=a}},fillHorizontal:{available:function(c,
b){return 1<b.length&&1<b[0].length},option:function(c){return c.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(c,b){for(var a=0,d=b.length;a<d;a++)for(var f=0,e=b[a].length;f<e;f++)b[a][f].set=b[a][0].data}},fillVertical:{available:function(c,b){return 1<b.length&&1<b[0].length},option:function(c){return c.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(c,b){for(var a=0,d=b.length;a<d;a++)for(var e=0,g=b[a].length;e<g;e++)b[a][e].set=b[0][e].data}},
cancel:{available:function(){return!1},option:function(c){return c.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}};g.version="2.1.0";g.defaults={alwaysAsk:!1,focus:null,columns:"",update:null,editor:null};g.classes={btn:"btn"};e(i).on("preInit.dt.autofill",function(c,b){if("dt"===c.namespace){var a=b.oInit.autoFill,d=j.defaults.autoFill;if(a||d)d=e.extend({},a,d),!1!==a&&new g(b,d)}});j.AutoFill=g;return j.AutoFill=g});
